package com.woniu.service.impl;

import com.woniu.entity.InpatientNursingRecord;
import com.woniu.mapper.InpatientNursingRecordMapper;
import com.woniu.service.INursingRecordService;
import com.woniu.utils.ResponseEnum;
import com.woniu.utils.ResponseUtil;
import com.woniu.utils.UserContext;
import com.woniu.vo.NursingRecordVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.text.ParseException;
import java.util.Date;
import java.util.List;

@Service
@Transactional
public class INursingRecordServiceImpl implements INursingRecordService {
    @Resource
    private InpatientNursingRecordMapper mapper;
    @Override
    public ResponseUtil recordList(Integer id) {
        List<NursingRecordVO> list = mapper.listNursingRecords(id);
        return list.size() > 0 ?
                ResponseUtil.get(ResponseEnum.OK,list)
                : ResponseUtil.get(ResponseEnum.FAIL);
    }

    @Override
    public ResponseUtil addRecord(InpatientNursingRecord record) throws ParseException {
//        record.setNrWorkerId(1);
        record.setNrWorkerId(UserContext.ContextUserId());
        record.setNrDate(new Date());
        Integer result = mapper.insertSelective(record);
        return result > 0 ?
                ResponseUtil.get(ResponseEnum.OK,record.getId())
                : ResponseUtil.get(ResponseEnum.FAIL);
    }
}
